﻿#region 头注释
/******************************************************************************
文件名称    :   SurgeryService.cs
创建日期    :   2011/5/13 6:49:31
功能描述    :   Surgery实体数据服务类
修改日志    :   
    2011-05-13 06:49  <马利>
*******************************************************************************/
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using Stone.Components.Entities;
using Dare.Utilities.Data;
using Stone.Data.Providers;

namespace Stone.Services.EntityServices
{
    /// <summary>
    /// Surgery实体数据服务类
    /// </summary>
    public class SurgeryService : EntityServiceTemplate<Surgery, long, SurgeryDataProvider>
    {
        public SurgeryService(Application app)
            : base(app)
        {
        }

        public bool DeleteSurgeryInfo(Surgery surgery)
        {
            SurgeryService surgeryService = Stone.Services.Application.Instance.GetDbService<SurgeryService>();
            SurgeryHardtubeService surgeryHardtubeService = Stone.Services.Application.Instance.GetDbService<SurgeryHardtubeService>();
            SurgeryKidneyService surgeryKidneyService = Stone.Services.Application.Instance.GetDbService<SurgeryKidneyService>();
            SurgerySofttubeService surgerySofttubeService = Stone.Services.Application.Instance.GetDbService<SurgerySofttubeService>();
            SurgeryInfectionService surgeryInfectionService = Stone.Services.Application.Instance.GetDbService<SurgeryInfectionService>();
            MediaFileService mediaFileService = Stone.Services.Application.Instance.GetDbService<MediaFileService>();

            try
            {
                if (surgery.KidneyId.HasValue) surgeryKidneyService.DeleteSurgeryKidneyInfo(surgeryKidneyService.Get(surgery.KidneyId.Value));
                if (surgery.SoftTubeId.HasValue) surgerySofttubeService.Delete(surgery.SoftTubeId.Value);
                if (surgery.HardTubeId.HasValue) surgeryHardtubeService.Delete(surgery.HardTubeId.Value);
                if (surgery.InfectionId.HasValue) surgeryInfectionService.Delete(surgery.InfectionId.Value);
                if (surgery.RecordFileId.HasValue) mediaFileService.Delete(surgery.RecordFileId.Value);

                return Delete(surgery.Id);
            }
            catch
            {
                return false;
            }
        }
    }
}
